Skip to content

gh-160561: Fix race in test_socket testFromFdError - #160930

Merged
asvetlov merged 2 commits into
python:mainfrom
asvetlov:fix-fromfd-test-race
Oct 30, 2026
Merged

asvetlov merged 2 commits into
python:mainfrom
asvetlov:fix-fromfd-test-race

Conversation

@asvetlov

@asvetlov asvetlov commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

testFromFdError (added in gh-160579) compares the process-wide fd count before and after a few rejected socket.fromfd() calls. In BasicTCPTest/BasicTCPTest2 the client thread runs concurrently and closes its socket in clientTearDown(); if that happens between the two fd_count() calls the test fails with AssertionError: 6 != 7. This was seen on the TSan (free-threading) job, e.g. https://github.com/python/cpython/actions/runs/40931791099/job/123724957337.

Wait on self.done (set at the end of clientTearDown()) before the first count, as check_shutdown() already does.

Verified by forcing the race (delaying the client thread and fromfd()): the old test fails with the same off-by-one, the new one passes. test_socket passes.

Needs backport to 3.15 and 3.14 together with gh-160579.

🤖 Generated with Claude Code

The client thread closes its socket in clientTearDown() concurrently
with the server-side test, so the process-wide fd count could drop
between the two os_helper.fd_count() calls.  Wait for the client thread
to finish before taking the first count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@asvetlov
asvetlov merged commit af79f49 into python:main Oct 30, 2026
50 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @asvetlov for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Oct 30, 2026

Copy link
Copy Markdown

GH-160955 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 30, 2026
@bedevere-app

bedevere-app Bot commented Oct 30, 2026

Copy link
Copy Markdown

GH-160956 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 30, 2026
asvetlov added a commit that referenced this pull request Oct 30, 2026
…#160956)

gh-160561: Fix race in test_socket testFromFdError (GH-160930)

The client thread closes its socket in clientTearDown() concurrently
with the server-side test, so the process-wide fd count could drop
between the two os_helper.fd_count() calls.  Wait for the client thread
to finish before taking the first count.
(cherry picked from commit af79f49)

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
asvetlov added a commit that referenced this pull request Oct 30, 2026
…#160955)

gh-160561: Fix race in test_socket testFromFdError (GH-160930)

The client thread closes its socket in clientTearDown() concurrently
with the server-side test, so the process-wide fd count could drop
between the two os_helper.fd_count() calls.  Wait for the client thread
to finish before taking the first count.
(cherry picked from commit af79f49)

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant